<?php
namespace app\common\model;

use app\common\BaseModel;
use think\model\concern\SoftDelete;

class Worker extends BaseModel
{
    protected $name = 'worker';

    use SoftDelete;
    protected $deleteTime = 'delete_time';

    protected $autoWriteTimestamp = true;

    /**
     * 根据登陆类型查找登陆信息
     * @param $query
     * @param $user
     * @return mixed
     */
    public function scopeWithUser($query, $user)
    {
        $loginType = System::getItem('login_type');
        if ( (int) $loginType === 1 ) {
            return $query->where('mobile', $user);
        } else {
            return $query->where('job_number', $user);
        }
    }
}
